#include "cgicontent.h"
#include "configuration.h"
#include <stdio.h>

void CgiContent::setFileName(const char * File){
	FileName = File;
}

void CgiContent::setGetQuery(const char * Query){
	GetQuery = Query;
}

void CgiContent::setPostQuery(const char * Query){
	PostQuery = Query;
}

std::string CgiContent::getResponse(){
	std::string cmd(Configuration::instance().envpath() + " QUERY_STRING=\"" + GetQuery + "\" \"" + FileName + "\"");
	FILE *P = popen(cmd.c_str(), "r");
	if (P) {
		char buf[1024];
		std::string S;
		//if (PostQuery) fputs(PostQuery, P);
		while (fgets(buf, 1023, P)) {
			S += buf;
		}
		pclose(P);
		return S;
	} else
		return std::string();
}
